<?php
	
	include_once("class/vo/ReturnDataVO.class.php");
	
	class DbInterface {
		
		var $host, $user, $password, $database, $charset;
		
		protected static $LINK_DATA_BASE = false;
		
		function __construct($host, $user, $password, $database, $charset = "utf8"){
			$this->host		= $host;
			$this->user     = $user;
			$this->database = $database;
			$this->password = $password;
			$this->charset 	= $charset;
			
			$this->connect();
		}
		
		private function connect(){
			if(self::$LINK_DATA_BASE){
				return true;
			} else {
				self::$LINK_DATA_BASE = mysql_connect($this->host, $this->user, $this->password);
				mysql_select_db($this->database, self::$LINK_DATA_BASE);
				mysql_set_charset($this->charset);
			}
		}
		
		function query($query, $insert_id = false){
			$result = mysql_query($query);

			if($errno = mysql_errno()){
				return new ReturnDataVO(false, mysql_error(), $errno);
			}

			if($insert_id){
				return $this->insert_id();
			} else {
				return new ReturnDataVO(true, $result);
			}
			
		}
		
		function close(){
			mysql_close(self::$LINK_DATA_BASE);
		}
		
		function fetch_row($query){
			return mysql_fetch_row($query);
		}

		function fetch_array($result){
			return mysql_fetch_array($result);
		}
	
		function fetch_object($result){
			return mysql_fetch_object($result);
		}
		
		function fetchArrayPush($result){
			$resultArray = array();
			while($tempArray = $this->fetch_array($result)){
				array_push($resultArray, $tempArray);
			}
			return $resultArray;
		}
		
		function insert_id(){
			return mysql_insert_id();
		}
		
	}
?>